package com.huika.dealontop.control.login.activity;

import android.content.Intent;
import android.os.Handler;
import android.os.Parcelable;
import android.os.SystemClock;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.huika.dealontop.R;
import com.huika.dealontop.control.base.BaseAct;
import com.huika.dealontop.control.myinfo.activity.MemberInfoDetailActivity;
import com.huika.dealontop.support.event.CallMainPagerChangeEvent;
import com.huika.dealontop.utils.UIUtils;
import com.huika.dealontop.views.TitleBarHelper;

import de.greenrobot.event.EventBus;

/**
 * Created by cailu on 2015/11/16.
 */
public class SuccessPageOne extends BaseAct {

    private TextView RSecond;
    private Handler mHandler = new Handler();;
    private String mStr;
    private int mVariable = 5;
    Parcelable mSuccessTwo;

    @Override
    public void setRootView() {
        setContentView(R.layout.activity_successpage_one);
    }

    @Override
    protected void initWidget() {
        super.initWidget();
        new TitleBarHelper(this, R.string.title_register);
        RSecond = (TextView) findViewById(R.id.tv_read_second);
        Button mBt = (Button) findViewById(R.id.register_bt_successpageone);
        mBt.setOnClickListener(this);
        setText();
        Intent intent = getIntent();

        String mSuccessTwo = intent.getStringExtra("SuccessTwo");
        //优惠券有效。

        if (!TextUtils.isEmpty(mSuccessTwo) && mSuccessTwo.equals("1")) {

            showToastMsg(getString(R.string.register_successpagetwo_dialog));
        }

    }

    public synchronized void setText() {
        switch (UIUtils.getString(R.string.common_lang)) {
            case "1":
                mStr = mVariable + "秒后进入团购列表页";
                break;
            case "2":
                mStr = "Redirect to deal list page in " + mVariable + "s…";
                break;
            case "3":
                mStr = "จะเปลี่ยนไปหน้ารายการดีลใน " + mVariable + "วินาท";
                break;

        }
        RSecond.setText(mStr);
    }

    @Override
    public void widgetClick(View v) {
        super.widgetClick(v);
        switch (v.getId()) {
            case R.id.register_bt_successpageone:
                skipActivity(aty, MemberInfoDetailActivity.class);
                break;
        }
    }

    @Override
    protected void initDataFromThread() {
        super.initDataFromThread();
        //Thread.sleep(5000);
        // boolean phoneorEmail = getIntent().getBooleanExtra("PhoneorEmail", false);

        for (int i = 5; i >= 1; i--) {
            final int tempI = i;
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    //RSecond.setText(tempI + "");
                    mVariable = tempI;
                    setText();


                }
            });
            SystemClock.sleep(1000);
        }

        aty.finish();
        EventBus.getDefault().post(new CallMainPagerChangeEvent(1));
    }
}
